package com.sk.sourcecircle.activity.main;

import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

import com.sk.sourcecircle.R;
import com.sk.sourcecircle.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by sk on 2018/1/19.
 */

public class ShareDetailsActivity extends BaseActivity {
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.help_web)
    WebView helpWeb;

    @Override
    protected int getContentView() {
        return R.layout.activity_share_details;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String url = getIntent().getStringExtra("url");
        helpWeb.loadUrl(url);
        WebSettings wSet = helpWeb.getSettings();
        wSet.setJavaScriptEnabled(true);
        helpWeb.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            { //  重写此方法表明点击网页里面的链接还是在当前的webview里跳转，不跳到浏览器那边
                view.loadUrl(url);
                return true;
            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if(keyCode == KeyEvent.KEYCODE_BACK && helpWeb.canGoBack()){
            helpWeb.goBack();
            return true;
        }else {
            finish();
        }
        return true;
    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }
}
